package com.cy.jt.controller;

import com.cy.jt.service.FileService;
import com.cy.jt.vo.ImageVo;
import com.cy.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/8/8 18:17
 */
@RestController
@RequestMapping("/file")
@CrossOrigin
public class FIleController {

    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public SysResult upload(MultipartFile file) throws IOException {
        ImageVo imageVo = fileService.upload(file);
        if (imageVo == null){
            return SysResult.fail();
        }
        return SysResult.success(imageVo);
    }

//    delete("/file/deleteFile", { params: { virtualPath: virtualPath } })
    @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }

}
